/**
 * 
 */
package t4j.arrays;

import java.util.Arrays;


public class ArrayOptions {

	public static void main(String[] args) {
		//1
		BerylliumSphere[] a ;
			
		//数组b并没有对象置入，但仍然可以询问数组的大小，因为b指向一个合法对象。
		//这样做有一个小缺点：你无法知道在此数组中确切地有多少元素，因为length只表示数组能够容纳多少元素
		//length是数组的大小，而不是实际保存的元素个数
		BerylliumSphere[] b = new BerylliumSphere[5];
		
		//新生成一个数组的对象时，其中所有的引用被自动化为null；
		//所以检查其中的引用是否为null，即可知道数组某个位置是否存在对象
		System.out.println("b: " + Arrays.toString(b));
		
		//3
		BerylliumSphere[] c = new BerylliumSphere[4];
		
		for(int i = 0 ; i < c.length ; i++)
			if(c[i] == null)
				c[i] = new BerylliumSphere();
		
		//聚集初始化
		BerylliumSphere[] d = {new BerylliumSphere(),new BerylliumSphere(),new BerylliumSphere()};
		
		//动态的聚集初始化
		a = new BerylliumSphere[]{
				new BerylliumSphere(),new BerylliumSphere()
		};
		
		System.out.println("a.length = " + a.length);
		System.out.println("b.length = " + b.length);
		System.out.println("c.length = " + c.length);
		System.out.println("d.length = " + d.length);
		
		a=d;//改了
		
		System.out.println("a.length = " + a.length );
		
		//基本类型数组
		int[] e;
		int[] f = new int[5];
		
		System.out.println("f: " + Arrays.toString(f));
		
		int[] g = new int[4];
		
		for(int i = 0; i < g.length ; i++)
			g[i] = i*i;
		
		int[] h = {11,37,93};
		
		System.out.println("f.length = " + f.length);
		System.out.println("g.length = " + g.length);
		System.out.println("h.length = " + h.length);
		
		e = h;
		
		System.out.println("e.length = " + e.length);
		
		//e ={1,2}; error :这种方式只能在声明时使用 int[] e = {1,2};
		e = new int[]{1,2};
		
		System.out.println("e.length = " + e.length);
		
		
	}
}
/* output
	b: [null, null, null, null, null]
	a.length = 2
	b.length = 5
	c.length = 4
	d.length = 3
	a.length = 3
	f: [0, 0, 0, 0, 0]
	f.length = 5
	g.length = 4
	h.length = 3
	e.length = 3
	e.length = 2
 */
